package com.google.code.dajly;

import java.io.IOException;
import java.net.URL;

import org.jdom.*;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;

public class JDomTest {

	public JDomTest(String xmlpath){
		
		SAXBuilder builder = new SAXBuilder();
		try {
			
			
//			Document doc = builder.build(new File(xmlpath));
			Document doc = builder.build(new URL(xmlpath).openStream());
			Namespace ns = Namespace.getNamespace("dajly", 
					"http://code.google.com/p/dajly/wiki/namespace");
			
			String locs = doc.getRootElement().getChild("channel").getChild("location", ns).getText();
			
			for(String _l : locs.split(";"))
				System.out.println(_l + "#");
			
			String buss = doc.getRootElement().getChild("channel").getChild("business", ns).getText();
			
			for(String _b : buss.split(";"))
				System.out.println(_b + "#");
			
			
			XMLOutputter xml = new XMLOutputter();
			xml.output(doc, System.out);
			
		} catch (JDOMException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				
	}
	
	public static void main(String... args){
		
		if (args.length > 0)
			new JDomTest(args[0]);
		else 
			new JDomTest("http://www.pigoz.eu/rss2e.xml");
		
	}

	
	
	
}
